<form action="index.php/opportunity/insert/" method="post" name="myform" id="myform" >
<div id="inline1">
<h2><span>销售机会信息</span></h2>
<table>
        <tr><th colspan="5">机会：</th></tr>
        <tr>
        	<td class="name" width="80"><span>*</span>机会主题：</td>
            <td colspan="4"><input name="subject" style=" width:427px;" type="text" class="text_width" id="subject" value=></input></td>
        </tr>
        <tr>
            <td class="name" width="80"><span>*</span>客户：</td>
            <td colspan="4">
            	<input name="customer_name" style=" width:427px;" type="text" id="customer_name" autocomplete="off" value=<?php echo $customer_name;?> ></input>
            </td>
        </tr>

        <tr>
        	<td class="name" style="padding-left:0px;" width="80"><span>*</span>客户联系人：</td>
            <td width="170" colspan="4">
                <select id="contacter_name" name="contacter_id" style="width:427px;">
					<?php foreach($contacters as $contacter_item):?>
					  <option value=<?= $contacter_item->id?>><?= $contacter_item->name?></option>
					<?php endforeach;?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="80">状态：</td>
            <td width="170" >
            	<select name="status">
                    <option value="跟踪">跟踪</option>
                    <option value="成功">成功</option>
                    <option value="失败">失败</option>
                    <option value="搁置">搁置</option>
                    <option value="失效">失效</option>
                </select>
            </td>
        </tr>
        <tr><th colspan="5">基本情况：</th></tr>
        <tr>
            <td class="name" width="80">发现时间：</td>
            <td width="170"><input type="text" class="datepicker" name="find_time" style="background:url(images/calendar.gif) right 1px no-repeat;" ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">来源：</td>
            <td width="170"><input type="text" name="source"></input></td>
        </tr>
        <tr>
            <td class="name" width="80">负责人：</td>
            <td width="170"><input type="text" name="principal" value="<?= $user_name=$this->session->userdata('username');?>"></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">提供人：</td>
            <td width="170"><input type="text" name="provider" ></input></td>
        </tr>
        <tr>
            <td class="gj_name">客户需求：</td>
            <td colspan="4"><textarea name="customer_demand" ></textarea></td>
        </tr>
        <tr><th colspan="5">预期：</th></tr>
        <tr>
            <td class="name" width="80">预计签单<br />日期：</td>
            <td width="170"><input type="text" name="expected_signing_date" class="datepicker"  style="background:url(images/calendar.gif) right 1px no-repeat;" ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80" style="padding-left:0px;">预期金额：</td>
            <td width="170"><input class="input_bg" type="text" name="expected_amount" ></input></td>
        </tr>
        <tr><th colspan="5">当前状态：</th></tr>
        <tr>
            <td class="name" width="80">阶段：</td>
            <td width="170">
            	<select name="stage">
                    <option value="沟通">沟通</option>
                    <option value="立项">立项</option>
                    <option value="招投标/谈判">招投标/谈判</option>
                    <option value="签合同">签合同</option>
                </select>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">可能性：</td>
            <td width="170">
            	<select name="possibility">
                    <option value="0">00%</option>
                    <option value="10">10%</option>
                    <option value="20">20%</option>
                    <option value="30">30%</option>
                    <option value="40">40%</option>
                    <option value="50">50%</option>
                    <option value="60">60%</option>
                    <option value="70">70%</option>
                    <option value="80">80%</option>
                    <option value="90">90%</option>
                    <option value="100">100%</option>
                </select>
            </td>
        </tr>

        <tr>
        	<td class="gj_name" width="80">阶段备注：</td>
            <td colspan="4"><textarea name="stage_remark"></textarea></td>
        </tr>
        <tr><td colspan="5">&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="opp_tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset""重置" /></td>
        </tr>
    </table>
</div>
</form>
<input type="hidden" id="type" value="0" ></input>
<script type="text/javascript">

$(function() {
		$( ".datepicker" ).datepicker();
});

	$("#opp_tijiao").click(function(){
		var error="";
		var customer_name=$.trim($("#customer_name").val());
		var contacter_name=$("#contacter_name").val();
		var subject=$.trim($("#subject").val());

		if(subject == ""){
			error="错误：\x0d";
			 error+="主题不允许为空,请填写\x0d";
			 if(subject == ''){
            	 $("#subject").focus();
              }
		}

		if(customer_name == ""){
			 if(error==""){
		    	 error="错误：\x0d";
			 }
             error+="客户名称不允许为空,请填写\x0d";
             if(subject != '' &&　customer_name == ""){
            	 $("#customer_name").focus();
                 }
	    }
	    if(contacter_name == null ){
		     if(error==""){
		    	 error="错误：\x0d";
			 }
	    	 error+="客户联系人不允许为空,请选择\x0d";
		}

		if(error != ""){
        	alert(error);
        }else{
            $("#myform").submit();
        }
	})
</script>